<html><head><meta charset="gb2312"/><title>OnError.pb</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<pre><font face="Courier New, Courier, mono"size="2"><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font><font color="#3A3966">;   PureBasic - OnError example file
</font><font color="#3A3966">;
</font><font color="#3A3966">;    (c) 2008 - Fantaisie Software
</font><font color="#3A3966">;
</font><font color="#3A3966">; ------------------------------------------------------------
</font><font color="#3A3966">;
</font> 
<b><font color="#3A3966">Procedure</font></b> <font color="#3A3966">ErrorHandler</font>()
 
  ErrorMessage$ = "A program error was detected:" +<font color="#3A3966"> Chr</font>(13) 
  ErrorMessage$ +<font color="#3A3966"> Chr</font>(13)
  ErrorMessage$ + "Error Message:   " +<font color="#3A3966"> ErrorMessage</font>()      +<font color="#3A3966"> Chr</font>(13)
  ErrorMessage$ + "Error Code:      " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorCode</font>())    +<font color="#3A3966"> Chr</font>(13)  
  ErrorMessage$ + "Code Address:    " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorAddress</font>()) +<font color="#3A3966"> Chr</font>(13)
 
  <b><font color="#3A3966">If</font></b> <font color="#3A3966">ErrorCode</font>() = <font color="#FF0000">#PB_OnError_InvalidMemory</font>   
    ErrorMessage$ + "Target Address:  " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorTargetAddress</font>()) +<font color="#3A3966"> Chr</font>(13)
  <b><font color="#3A3966">EndIf</font></b>
 
  <b><font color="#3A3966">If</font></b> <font color="#3A3966">ErrorLine</font>() = -1
    ErrorMessage$ + "Sourcecode line: Enable OnError lines support to get code line information." +<font color="#3A3966"> Chr</font>(13)
  <b><font color="#3A3966">Else</font></b>
    ErrorMessage$ + "Sourcecode line: " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorLine</font>()) +<font color="#3A3966"> Chr</font>(13)
    ErrorMessage$ + "Sourcecode file: " +<font color="#3A3966"> ErrorFile</font>() +<font color="#3A3966"> Chr</font>(13)
  <b><font color="#3A3966">EndIf</font></b>
 
  ErrorMessage$ +<font color="#3A3966"> Chr</font>(13)
  ErrorMessage$ + "Register content:" +<font color="#3A3966"> Chr</font>(13)
 
  <b><font color="#3A3966">CompilerSelect</font></b> <font color="#FF0000">#PB_Compiler_Processor</font> 
    <b><font color="#3A3966">CompilerCase</font></b> <font color="#FF0000">#PB_Processor_x86</font>
      ErrorMessage$ + "EAX = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_EAX</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "EBX = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_EBX</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "ECX = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_ECX</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "EDX = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_EDX</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "EBP = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_EBP</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "ESI = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_ESI</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "EDI = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_EDI</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "ESP = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_ESP</font>)) +<font color="#3A3966"> Chr</font>(13)
 
    <b><font color="#3A3966">CompilerCase</font></b> <font color="#FF0000">#PB_Processor_x64</font>
      ErrorMessage$ + "RAX = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_RAX</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "RBX = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_RBX</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "RCX = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_RCX</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "RDX = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_RDX</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "RBP = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_RBP</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "RSI = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_RSI</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "RDI = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_RDI</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "RSP = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_RSP</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "Display of registers R8-R15 skipped."         +<font color="#3A3966"> Chr</font>(13)
 
    <b><font color="#3A3966">CompilerCase</font></b> <font color="#FF0000">#PB_Processor_PowerPC</font>
      ErrorMessage$ + "r0 = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_r0</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "r1 = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_r1</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "r2 = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_r2</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "r3 = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_r3</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "r4 = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_r4</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "r5 = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_r5</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "r6 = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_r6</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "r7 = " +<font color="#3A3966"> Str</font>(<font color="#3A3966">ErrorRegister</font>(<font color="#FF0000">#PB_OnError_r7</font>)) +<font color="#3A3966"> Chr</font>(13)
      ErrorMessage$ + "Display of registers r8-R31 skipped."       +<font color="#3A3966"> Chr</font>(13)
 
  <b><font color="#3A3966">CompilerEndSelect</font></b>
 
<font color="#3A3966">  MessageRequester</font>("OnError example", ErrorMessage$)
  <b><font color="#3A3966">End</font></b>
 
<b><font color="#3A3966">EndProcedure</font></b>
 
<font color="#3A3966">; Setup the error handler.
</font><font color="#3A3966">;
</font><font color="#3A3966">OnErrorCall</font>(@ErrorHandler())
 
<font color="#3A3966">MessageRequester</font>("OnError example", "Executing some code with errors. The debugger should be turned off.")
 
 
<font color="#3A3966">; Write to protected memory
</font><font color="#3A3966">;
</font><font color="#3A3966">PokeS</font>(123, "The quick brown fox jumped over the lazy dog.")
 
<font color="#3A3966">; Division by zero
</font><font color="#3A3966">;
</font>a = 0
a = 1 / a
 
<font color="#3A3966">; Generate an error manually
</font><font color="#3A3966">;
</font><font color="#3A3966">RaiseError</font>(<font color="#FF0000">#PB_OnError_IllegalInstruction</font>)
 
 
<font color="#3A3966">; This should not be displayed
</font><font color="#3A3966">;
</font><font color="#3A3966">MessageRequester</font>("OnError example", "Execution finished normally.")
<b><font color="#3A3966">End</font></b>
</font></pre>
</body></html>
